import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/page/home/area_compete/widgets/widgets.dart';
import 'package:leader_help/page/home/models/province_level.dart';
import 'package:leader_help/utils/component/list/section.dart';
import 'package:leader_help/utils/util.dart';

import 'index.dart';

class AreaCompeteController extends GetxController
    with GetSingleTickerProviderStateMixin {
  AreaCompeteController();

  final state = AreaCompeteState();

  void getData() {
    var items = [
      ProvinceLevelModel(province: '河南省', isCurrent: true),
      ProvinceLevelModel(province: '湖北省'),
      ProvinceLevelModel(province: '安徽省'),
      ProvinceLevelModel(province: '山西省'),
      ProvinceLevelModel(province: '湖南省'),
      ProvinceLevelModel(province: '河北省'),
    ];
    state.list = [
      SectionModel(
          index: 0,
          sectionHeader: const AreaCompeteHeader(),
          itemBuilder: (ctx, index) {
            var _item = items[index];
            return GestureDetector(
              onTap: () => actionCell(_item),
              child: AreaCompeteCell(
                mod: _item,
                index: index,
              ),
            );
          },
          items: items)
    ];
    update();
  }

  void actionCell(ProvinceLevelModel mod) {
    if (mod.isCurrent == true) {
      return;
    }
    Get.toNamed(RouterPath.province_level, arguments: {
      'level': mod,
      'current': state.list.first.items.first,
    });
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    state.tabTitles = [
      '中部崛起',
      '西部大开发',
      '东部现代化',
      '东北振兴',
      '京津冀协同发展',
      '粤港澳大湾',
      '长三角一体化发展',
      '长江经济带发展',
    ];
    state.tabCtrl = TabController(length: state.tabTitles.length, vsync: this);
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
    getData();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
